package com.kgc.service.Impl.user;

import com.kgc.dao.mapper.user.OwnerMapper;
import com.kgc.entity.User;
import com.kgc.service.interf.user.OwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author hyj
 * @time 2024/4/2 15:58
 * @describe
 */
@Service("ownerService")
public class OwnerServiceImpl implements OwnerService {
    @Autowired
    private OwnerMapper ownerMapper;

    @Override
    public User getOwner(Integer id) {
        return ownerMapper.getOwner(id);
    }

    @Override
    public int updateOwner(Integer id, String username, String email) {
        User u1 = ownerMapper.selectByUsername(username);
        User u2 = ownerMapper.selectByEmail(email);
        if (u1 != null && !u1.getUserId().equals(id)) {
            // username重复
            return -1;
        }
        if (u2 != null && !u2.getUserId().equals(id)) {
            // email重复
            return -2;
        }
        return ownerMapper.updateOwner(id, username, email);
    }
}
